package com.ctshk.rpc.goods.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.goods.dto.FreightTemplateDTO;
import com.ctshk.rpc.goods.entity.FreightTemplate;
import com.ctshk.rpc.goods.mapper.provider.FreightTemplateProvider;
import com.ctshk.rpc.goods.req.FreightTemplatePageReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

/**
 * <p>
 * 运费模板表 Mapper 接口
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-09
 */
public interface FreightTemplateMapper extends BaseMapper<FreightTemplate> {
	
	@SelectProvider(type = FreightTemplateProvider.class, method = "findFreightTemplateByAll")
    IPage<FreightTemplateDTO> findFreightTemplateByAll(IPage<FreightTemplateDTO> page, FreightTemplatePageReq pageReq);
	
	@Select("SELECT t.id, t.template_name FROM `ctshk-goods`.t_freight_template t WHERE t.is_deleted = 0")
	List<FreightTemplateDTO> findTemplateName();

	@Select("SELECT t.id, t.template_name FROM `ctshk-goods`.t_freight_template t WHERE t.is_deleted = 0 and t.template_name = #{templateName}")
	List<FreightTemplateDTO> findTemplateNameList(@Param("templateName") String templateName);

	/**
	 * 运费模板查询
	 * @param id
	 * @return
	 */
	@Select({
			"SELECT id,template_number,template_name,pricing_method,is_free_shipping,cash_on_delivery,sort,create_id,modified_id,is_deleted,gmt_create,gmt_modified FROM `ctshk-goods`.t_freight_template WHERE id=#{id}"
	})
	FreightTemplate selectTemplateById(@Param("id") Long id);
}
